﻿using System.Drawing;
using System.Windows.Forms;

namespace Medicalsystem.MCP.FormDesigner.Ctl
{
    public partial class ctl_ModelDesignObject : DevExpress.XtraEditors.XtraUserControl
    {
        public ctl_ModelDesignObject(string modelID, DevExpress.XtraEditors.XtraForm modeForm)
        {
            InitializeComponent();

            _modelID = modelID;
            _modelForm = modeForm;

            _modelForm.TopLevel = false;
            _modelForm.ControlBox = false;
            _modelForm.FormBorderStyle = FormBorderStyle.Sizable;

            _modelForm.Show();
            this.Panel_ModelContainer.Controls.Add(_modelForm);
        }

        private string _modelID = string.Empty;
        private DevExpress.XtraEditors.XtraForm _modelForm;

        /// <summary>
        /// 按键的X坐标
        /// </summary>
        private int Point_Y;

        /// <summary>
        /// 模板编号
        /// </summary>
        public string ModelID
        {
            get { return _modelID; }
        }

        /// <summary>
        /// 模板
        /// </summary>
        public DevExpress.XtraEditors.XtraForm ModelForm
        {
            get { return _modelForm; }
        }

        /// <summary>
        /// 模板容器
        /// </summary>
        public DevExpress.XtraEditors.PanelControl Container_Model
        {
            get { return this.Panel_ModelContainer; }
        }

        /// <summary>
        /// 组件类控件容器
        /// </summary>
        public FlowLayoutPanel Container_Com
        {
            get { return this.Panel_ComContainer; }
        }

        /// <summary>
        /// 组件控件容器显示
        /// </summary>
        public bool Container_ComVisible
        {
            set { this.panel_bottom.Visible = value; }
        }

        private void panel_move_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                Point_Y = System.Windows.Forms.Control.MousePosition.Y;
            }
        }

        private void panel_move_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                Point mousePos = System.Windows.Forms.Control.MousePosition;
                this.panel_bottom.Height = this.panel_bottom.Height - (mousePos.Y - Point_Y);

                if (this.panel_bottom.Height < 5)
                {
                    this.panel_bottom.Height = 5;
                }
                this.panel_bottom.Refresh();
            }
        }
    }
}